using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using HengTong.Model.Db.Hr.Attendance;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Hr.SysAttendanceRecordVms
{
    public partial class SysAttendanceRecordListVm : BaseListVm<SysAttendanceRecordView, SysAttendanceRecordSearcher>
    {

        protected override IEnumerable<IGridColumn<SysAttendanceRecordView>> InitGridHeader()
        {
            return new List<GridColumn<SysAttendanceRecordView>>{
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.AttendanceShiftGroupName),
                this.MakeGridHeader(x => x.ShiftType),
                this.MakeGridHeader(x => x.ScheduleType),
                this.MakeGridHeader(x => x.Status),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeader(x => x.SubstitutePersonName),
                this.MakeGridHeader(x => x.AttendanceResult),
                this.MakeGridHeader(x => x.LateMinutes),
                this.MakeGridHeader(x => x.EarlyLeaveMinutes),
                this.MakeGridHeader(x => x.WorkMinutes),
                this.MakeGridHeader(x => x.MissingPunchCount),
                this.MakeGridHeader(x => x.IsAbnormal),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysAttendanceRecordView> GetSearchQuery()
        {
            var query = DC.Set<SysAttendanceRecord>()
                .CheckEqual(Searcher.PersonId, x=>x.PersonId)
                .CheckEqual(Searcher.AttendanceShiftGroupId, x=>x.AttendanceShiftGroupId)
                .CheckEqual(Searcher.ShiftType, x=>x.ShiftType)
                .CheckEqual(Searcher.ScheduleType, x=>x.ScheduleType)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckEqual(Searcher.SubstitutePersonId, x=>x.SubstitutePersonId)
                .CheckEqual(Searcher.AttendanceResult, x=>x.AttendanceResult)
                .CheckEqual(Searcher.IsAbnormal, x=>x.IsAbnormal)
                .Select(x => new SysAttendanceRecordView
                {
				    ID = x.ID,
                    PersonName = x.Person.Name,
                    AttendanceShiftGroupName = x.AttendanceShiftGroup.Name,
                    ShiftType = x.ShiftType,
                    ScheduleType = x.ScheduleType,
                    Status = x.Status,
                    Remark = x.Remark,
                    SubstitutePersonName = x.SubstitutePerson.Name,
                    AttendanceResult = x.AttendanceResult,
                    LateMinutes = x.LateMinutes,
                    EarlyLeaveMinutes = x.EarlyLeaveMinutes,
                    WorkMinutes = x.WorkMinutes,
                    MissingPunchCount = x.MissingPunchCount,
                    IsAbnormal = x.IsAbnormal,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }
}
